/*
 *  mini-SaaS
 *  Application for developing Software as a Service (SaaS) 
 *  Copyright (c) 2011 Anand Sudhakaran, Bryce Holton, Chao Zhang
 *  ASU
 *
 *  This file is part of mini-SaaS.
 *
 *  mini-SaaS is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  mini-SaaS is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.

 *  You should have received a copy of the GNU General Public License
 *  along with mini-SaaS; if not, see <http://www.gnu.org/licenses/>. 
 *
 */

package loginbean;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class GUIController extends HttpServlet
{
	private static final long serialVersionUID = 1L;
	public void init ( ServletConfig conf ) throws ServletException
	{
		super.init(conf);
	}
	public void doPost ( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException
	{
		HttpSession session = req.getSession( true );
		int tenantId = Integer.parseInt(session.getAttribute("tenantid").toString());
		
		String url = null;
		String viewcmd = req.getParameter( "viewcmd" );
		switch( viewcmd.charAt( 0 ) )
		{
			case 'A':
			{
				String header = req.getParameter( "header" );
				String footer = req.getParameter( "footer" );
				String sidebar = req.getParameter( "sidebar" );
				GraphicalUserInterface.insertNewGui(tenantId, header, footer, sidebar);
				url = "/welcome.jsp";
			}
		}
		ServletContext sc = getServletContext();
		RequestDispatcher rd = sc.getRequestDispatcher(url);
		rd.forward(req, res);
	}
}
